<?php
/*
* Smarty plugin
* --------------------------------------------------------------------------
* File:     modifier.int2str.php
* Type:     modifier
* Name:     int2str
* Version:  .1
* Date:     July 13, 2007
* Purpose:  Outputs alternative text to numeric variables.
*           Example:
* Install:  Drop into the plugin directory.
* Author:   Novachok Alexandr <novachok@ukr.net>
* --------------------------------------------------------------------------
*/

function smarty_modifier_int2str_money($int,$lang='ru')
{
   $int = sprintf("%.2f", $int);
   $decimal = substr($int, 0, -3);
   $float   = substr($int, -2, 2);
   $lenth   = strlen($decimal);
   $result  = '';

   $words['ua']['ds']  = 'грн.';
   $words['ua']['fs']  = 'коп.';
   $words['ua'][0]     = 'нуль';
   $words['ua'][1]     = 'одна';
   $words['ua'][2]     = 'дві';
   $words['ua'][3]     = 'три';
   $words['ua'][4]     = 'чотири';
   $words['ua'][5]     = 'пять';
   $words['ua'][6]     = 'шість';
   $words['ua'][7]     = 'сім';
   $words['ua'][8]     = 'вісім';
   $words['ua'][9]     = 'девять';
   $words['ua'][10]    = 'десять';
   $words['ua'][11]    = 'одинадцять';
   $words['ua'][12]    = 'дванадцять';
   $words['ua'][13]    = 'тринадцять';
   $words['ua'][14]    = 'чотирнадцять';
   $words['ua'][15]    = 'пятнадцять';
   $words['ua'][16]    = 'шістнадцять';
   $words['ua'][17]    = 'сімнадцять';
   $words['ua'][18]    = 'вісімнадцять';
   $words['ua'][19]    = 'девятнадцять';
   $words['ua'][20]    = 'двадцять';
   $words['ua'][30]    = 'тридцять';
   $words['ua'][40]    = 'сорок';
   $words['ua'][50]    = 'пятьдесят';
   $words['ua'][60]    = 'шістьдесят';
   $words['ua'][70]    = 'сімдесят';
   $words['ua'][80]    = 'вісімдесят';
   $words['ua'][90]    = 'девяносто';
   $words['ua'][100]   = 'сто';
   $words['ua'][200]   = 'двісті';
   $words['ua'][300]   = 'триста';
   $words['ua'][400]   = 'чотириста';
   $words['ua'][500]   = 'пятьсот';
   $words['ua'][600]   = 'шістьсот';
   $words['ua'][700]   = 'сімьсот';
   $words['ua'][800]   = 'вісімсот';
   $words['ua'][900]   = 'девятьсот';
   $words['ua']['1k']  = 'тисяча';
   $words['ua']['1ks'] = 'тисяч';
   $words['ua']['1m']  = 'міліон';
   $words['ua']['1ms'] = 'міліона';

   if ($decimal > 99)
   {
      $result .= $words[$lang][$decimal[0].'00'];
      if($decimal[1].$decimal[2] > 9 && $decimal[1].$decimal[2] < 20)
      {
         $result .= ' ';
         $result .= $words[$lang][$decimal[1].$decimal[2]];
      } else
      {
         if($decimal[1] != 0)
         {
            $result .= ' ';
            $result .= $words[$lang][$decimal[1].'0'];
         }
         if($decimal[2] != 0)
         {
            $result .= ' ';
            $result .= $words[$lang][$decimal[2]];
         }
      }
   } elseif ($decimal > 19)
   {
      $result .= $words[$lang][$decimal[0].'0'];
      $result .= ' ';
      if($decimal[1] != 0) $result .= $words[$lang][$decimal[1]];
   } elseif ($decimal < 20)
   {
      $result .= $words[$lang][$decimal];
   }

   if($result != '')
   {
      $result .= ' ' . $words[$lang]['ds'];
   }

   $result .= ', ' . $float . ' ' . $words[$lang]['fs'];

   return $result;
}

?>